/*
* 通用js块
* A.Menu菜单
* B.Search搜索
* C.Filter过滤
* D.Department部门
* */
var EPS=EPS||{};
EPS.menu={
    i:function(ck){
        var mb=function(ck,nk){
            return (ck==nk||(nk=='index'&&ck==''))?'active':'';
        };
        document.getElementById("menuBox").innerHTML='<a href="index.html" title="首页" class="menu-item '+mb(ck,'index')+'"><i class="fui-font fui-font-e9b3"></i><span>首页</span></a>' +
            '<a href="employ.html" title="招聘登记" class="menu-item '+mb(ck,'employ')+'"><i class="fui-font fui-font-e9b9"></i><span>招聘登记</span></a>' +
            '<a href="staff.html" title="员工信息管理" class="menu-item '+mb(ck,'staff')+'"><i class="fui-font fui-font-e9b8"></i><span>员工信息管理</span></a>' +
            '<a href="contract.html" title="劳动合同" class="menu-item '+mb(ck,'contract')+'"><i class="fui-font fui-font-e9ab"></i><span>劳动合同</span></a>' +
            '<a href="assurance.html" title="社保公积金" class="menu-item '+mb(ck,'assurance')+'"><i class="fui-font fui-font-e9ad"></i><span>社保公积金</span></a>' +
            '<a href="salary.html" title="工资薪酬" class="menu-item '+mb(ck,'salary')+'"><i class="fui-font fui-font-e9b7"></i><span>工资薪酬</span></a>' +
            '<a href="attendance.html" title="考勤统计" class="menu-item '+mb(ck,'attendance')+'"><i class="fui-font fui-font-e9aa"></i><span>考勤统计</span></a>' +
            '<a href="train.html" title="培训记录" class="menu-item '+mb(ck,'train')+'"><i class="fui-font fui-font-e9ac"></i><span>培训记录</span></a>' +
            '<a href="experience.html" title="体验记录" class="menu-item '+mb(ck,'experience')+'"><i class="fui-font fui-font-e9b4"></i><span>体验记录</span></a>' +
            '<a href="statistics.html" title="统计分析" class="menu-item '+mb(ck,'statistics')+'"><i class="fui-font fui-font-e9b5"></i><span>统计分析</span></a>' +
            '<a href="system.html" title="系统管理" class="menu-item '+mb(ck,'system')+'"><i class="fui-font fui-font-e9b6"></i><span>系统管理</span></a>';
    },
    btn:function(){
        var box=document.getElementById('bodyBox');
        if(fui.hasClass(box,'body-extend')){
            fui.removeClass(box,'body-extend')
        }else{
            fui.addClass(box,'body-extend')
        }
    }
};

EPS.search={
    i:function(){
        var t=this;
        var poll=function(){
            if(!fui.$){
                setTimeout(poll,20)
            }else{
                t.com();
            }
        };
        poll();
    },
    com:function(){
        fui.$('.search-ipt[data-input]').on('input',function(){
            var _t=fui.$(this),f=_t.data('input');
            f = eval(f);
            f.call(this,_t.val())
        });
        fui.$('.search-ipt[data-enter]').on('keydown',function(e){
            var _t=fui.$(this),f=_t.data('enter');
            if(e.keyCode==13){
                f = eval(f);
                f.call(this,_t.val())
            }
        });
    }
};
EPS.search.i();

EPS.filter={
    text:function(field,title){
        return '<div class="tips-filter fui-form" data-field="'+field+'" data-title="'+title+'">' +
                    '<div class="tf-hd">显示条件行：'+title+'</div>' +
                    '<div class="tf-conditions">' +
                        '<div class="form-item-select">' +
                            '<div class="form-select-title"><input type="text" readonly placeholder="请选择条件" value="等于" class="form-item-input"></div>'+
                            '<ol class="form-select-option" fm-name="conditions_1">' +
                                '<li fm-value="0">等于</li>'+
                                '<li fm-value="1">不等于</li>'+
                                '<li fm-value="2">小于</li>'+
                                '<li fm-value="3">小于等于</li>'+
                                '<li fm-value="4">大于</li>'+
                                '<li fm-value="5">大于等于</li>'+
                                '<li fm-value="6">始于</li>'+
                                '<li fm-value="7">止于</li>'+
                                '<li fm-value="8">包含</li>'+
                                '<li fm-value="9">不包含</li>'+
                            '</ol><input type="hidden" name="conditions_1" value="0">'+
                        '</div>'+
                        '<input type="text" class="select-value" data-sv="conditions_1">'+
                    '</div>' +
                    '<div class="tf-between">' +
                         '<div class="form-item-radio fui-radio-checked" fm-name="between" fm-value="and"><i class="fui-font fui-font-radio"></i><span>并且</span></div>' +
                         '<div class="form-item-radio" fm-name="between" fm-value="or"><i class="fui-font fui-font-radio"></i><span>或者</span></div>' +
                        '<input type="hidden" name="between" value="and"></div>' +
                    '<div class="tf-conditions">' +
                        '<div class="form-item-select">' +
                            '<div class="form-select-title"><input type="text" readonly placeholder="请选择条件" value="等于" class="form-item-input"></div>'+
                            '<ol class="form-select-option" fm-name="conditions_2">' +
                                '<li fm-value="0">等于</li>'+
                                '<li fm-value="1">不等于</li>'+
                                '<li fm-value="2">小于</li>'+
                                '<li fm-value="3">小于等于</li>'+
                                '<li fm-value="4">大于</li>'+
                                '<li fm-value="5">大于等于</li>'+
                                '<li fm-value="6">始于</li>'+
                                '<li fm-value="7">止于</li>'+
                                '<li fm-value="8">包含</li>'+
                                '<li fm-value="9">不包含</li>'+
                            '</ol><input type="hidden" name="conditions_2" value="0">'+
                        '</div>'+
                        '<input type="text" class="select-value" data-sv="conditions_2">'+
                    '</div>' +
                '<div class="tf-zdy">自定义表达示</div>' +
                '<textarea class="tf-textarea"></textarea>'+
            '</div>'
    },
    i:function(){
        var _Body=fui.$('body');
        var nr=['=','<>','<','<=','>','>=','like','like','like','not like'];
        var vFun=function(idx,val){
            var nVal;
            switch (idx){
                case '6':
                    nVal=val+'%';
                    break;
                case '7':
                    nVal='%'+val;
                    break;
                case '8':
                case '9':
                    nVal='%'+val + '%';
                    break;
                default:
                    nVal=val;
                    break;
            }
            return nVal
        };
        var tFun=function(v1,v2,between){
            var tf=fui.$('.tips-filter'),
                tb=tf.find('.tf-textarea'),
                sv1=tf.find('[data-sv="conditions_1"]').val(),
                sv2=tf.find('[data-sv="conditions_2"]').val(),
                tt='['+tf.data('title')+']';
            v1=v1||tf.find('[name="conditions_1"]').val();
            v2=v2||tf.find('[name="conditions_2"]').val();
            between=between||tf.find('[name="between"]').val();
            if(sv1!=''&&sv2!=''){
                tb.val(tt + ' ' + nr[v1] + ' ' + vFun(v1,sv1) +' '+ between + ' ' + tt + ' ' + nr[v2] + ' ' + vFun(v2,sv2))
            }else if(sv1!=''){
                tb.val(tt + ' ' + nr[v1] + ' ' + vFun(v1,sv1))
            }else if(sv2!=''){
                tb.val(tt + ' ' + nr[v2] + ' ' + vFun(v2,sv2))
            }
        };
        _Body.on('input','.select-value',function(){
            tFun();
        });
        _Body.on('click','.tips-filter .form-select-option li',function(){
            var idx=fui.$(this).attr('fm-value'),tp=fui.$(this).parent('.form-select-option');
            tp.attr('fm-name').split('_')[1]==1?tFun(idx):tFun('',idx);
        });
        _Body.on('click','.tips-filter .form-item-radio',function(){
            var _t=fui.$(this),between=_t.attr('fm-value');
            if(!_t.hasClass('fui-radio-checked')){
                tFun("","",between)
            }
        });
    }
};

EPS.depart={
    i:function(){
        this.search();
        this.btn();
    },
    search:function(){},
    btn:function(){
        var _Body=fui.$('body');
        _Body.on('click','.dpb-hd',function(){
            var _t=fui.$(this),ta=_t.parent('.dp-box');
            if(ta.hasClass('dp-checked')){
                ta.removeClass('dp-checked');
                ta.find('.dp-checked').removeClass('dp-checked');
            }else{
                ta.addClass('dp-checked')
            }
        });
        _Body.on('click','.dp-box .dpb-item',function(){
            var _t=fui.$(this);
            if(_t.hasClass('checked')){
                _t.removeClass('checked')
            }else{
                _t.addClass('checked');
            }
        });
    }
};

//当初始化完毕以后执行
(function(){
    var poll=function(){
        if(!fui.$){
            setTimeout(poll,20);
        }else{
            EPS.filter.i();
            EPS.depart.i();
        }
    };
    poll();
}());



